package rabbitmq.dwj;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class Producer {

    private final static String queue_name="hello";

    public static void main(String[] args) throws Exception {
        ConnectionFactory connection=new ConnectionFactory();
        connection.setHost("212.64.48.240");
        connection.setPassword("123");
        connection.setPort(5672);
        connection.setUsername("admin");

        try(Connection con = connection.newConnection(); Channel channel = con.createChannel()){
             channel.queueDeclare(queue_name,false,false,false,null);
             String message="hello world";
             channel.basicPublish("",queue_name,null,message.getBytes());
            System.out.println("消息发送成功");
        }
    }
}
